package com.example.community.login;

import com.example.community.dao.*;
import com.example.community.model.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;

@WebServlet(urlPatterns = "/controlpanel")
public class ControlpanelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取用户总数
        UsersDao usersDao = new UsersDao();
        int usersize = usersDao.fandByAll().size();

        // 获取房间总数
        RoomDao roomDao = new RoomDao();
        int roomsize = roomDao.fandByAll().size();
        int roomsizenull = roomDao.selectNull().size();
        // 剩余房间

        // 获取车位总数
        ParkingDao parkingDao = new ParkingDao();
        int parkingsize = parkingDao.fandByAll().size();
        int parkingsizenull = parkingDao.selectNull().size();

        // 获取投诉总数
        ComplaintDao complaintDao = new ComplaintDao();
        int complaintsize = complaintDao.fandAll().size();
        int complaintsizeStatic = complaintDao.fandAllStatic().size();

        // 维修总数
        RepairDao repairDao = new RepairDao();
        int repairsize = repairDao.fandByAll().size();
        int repairsizeStatic = repairDao.fandByAllStatic().size();

        // 账单总数
        PaymanagerDao paymanagerDao = new PaymanagerDao();
        int paysize = paymanagerDao.fandByAll().size();
        int paysizeStatic = paymanagerDao.fandByAllStatic().size();

        req.setAttribute("usersize",usersize);
        req.setAttribute("roomsize",roomsize);
        req.setAttribute("parkingsize",parkingsize);
        req.setAttribute("complaintsize",complaintsize);
        req.setAttribute("repairsize",repairsize);
        req.setAttribute("paysize",paysize);

        req.setAttribute("roomsizenull",roomsizenull);
        req.setAttribute("parkingsizenull",parkingsizenull);
        req.setAttribute("complaintsizeStatic",complaintsizeStatic);
        req.setAttribute("repairsizeStatic",repairsizeStatic);
        req.setAttribute("paysizeStatic",paysizeStatic);

        req.getRequestDispatcher("/WEB-INF/controlpanel.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
